
#include "C:\SAFIRE\Y\Y_BIFn\Y_BIFn.y.h"

#include "C:\SAFIRE\Y\PH_SL.y.h"

#include "C:\SAFIRE\Y\Mgt_SL.y.h"

#include "C:\SAFIRE\Y\ConfigUdp_TP.y.h"

#include "C:\SAFIRE\Users\SIP_USER\ws\SIP\source\Common_LIB\Scenario_HTML_Gen.y.h"

#include "C:\SAFIRE\USERS\SIP_USER\ws\SIP\source\SIP_LIB\SIP_LIB.y.h"


typedef SIP_ST_CC_OE_CE_V [SIP_Signals_T SIP_G, PH_SL UDP_Data_G, Mgt_SL UDP_Mgt_G]
{
            
    TIMER SIGNAL        TSupervisor();
    TIMER SIGNAL        TAct_Rq();
    TIMER SIGNAL        TResponse();
    TIMER SIGNAL        TStart();
	       
    Request_T           Request_RX_1;
    
    Response_T          Response_T_TX_1;
    Response_T          Response_T_TX_2;
    Response_T          Response_T_RX_1;
    Response_T          Response_T_RX_2;
    
    Request_Line_T      Request_Line;
    Message_Headers_T   Message_Headers;
    Message_Body_T      Message_Body;
    Status_Line_T       Status_Line;
    
    PH_SL               PH_SL_S;
    SIP_Signals_T       SIP_Signal;    
    Config_UDP_T        ConfigUDP;
    
    STRING              CRLF;
        
    STRING              ScenarioName;
    STRING              ScenarioDecription;
    STRING              HTML_Title;
    STRING              HTMLFilePath;
    STRING              Mode;
    NUMBER              HTML_File;
	NUMBER				Retry_Cancel;
	
	SIP_Addr_Spec_T		SUT_Addr;
	SIP_Addr_Spec_T		Tester_Addr;
	
  
    SUT_Addr.SIP_URI.UserInfo.User = "228";
	SUT_Addr.SIP_URI.UserInfo.Password = NULL;	
	SUT_Addr.SIP_URI.HostPort.Host = "10.0.1.40";
	SUT_Addr.SIP_URI.HostPort.Port = 5060;	
	SUT_Addr.SIP_URI.URI_Parameters = NULL;
	SUT_Addr.SIP_URI.URI_Headers = NULL;
	
    Tester_Addr.SIP_URI.UserInfo.User = "1000";
	Tester_Addr.SIP_URI.UserInfo.Password = NULL;	
	Tester_Addr.SIP_URI.HostPort.Host = "10.0.1.109";
	Tester_Addr.SIP_URI.HostPort.Port = 5060;	
	Tester_Addr.SIP_URI.URI_Parameters = NULL;
	Tester_Addr.SIP_URI.URI_Headers = NULL;
		
    
    Mode= "ab";
    HTMLFilePath= "C:\\SAFIRE\\Temp\\SIP_ST_CC_OE_CE_V.html";    
    
    HTML_File= OpenFile( HTMLFilePath,
                         Mode);
    IF (HTML_File EQ 0)
    {
        Print( "SIP_ST_CC_OE_CE - Can't open C:\\SAFIRE\\Temp\\");
        Print( "SIP_ST_CC_OE_CE - Please create this directory C:\\SAFIRE\\Temp\\");
        STOP;
    }
                             
    HTML_Title = "SIP_ST_CC_OE_CE_V";
    ScenarioName = "SIP_ST_CC_OE_CE_V";
    ScenarioDecription = "basic call - passive part";
    Scenario_Gen_HTML_Header( HTML_File,
                              HTML_Title,
                              ScenarioName,
                              ScenarioDecription);

    START TStart FOR 1000;
    Print("\n\nScenario_1 : ---  started");
    
    ? .TStart()
    {
         Print("\n\nScenario_1 : ---  started");
         :: Preamble;
    }        
     
    
    STATE Preamble
    {        
        Print("SIP_ST_CC_OE_CE - Start UDP config");
        ConfigUDP.Src.IpAddress=        Tester_Addr.SIP_URI.HostPort.Host;
        ConfigUDP.Src.Port=             Tester_Addr.SIP_URI.HostPort.Port;
        
        ConfigUDP.Dst.IpAddress=        SUT_Addr.SIP_URI.HostPort.Host;
        ConfigUDP.Dst.Port=             SUT_Addr.SIP_URI.HostPort.Port;
        
        ConfigUDP.MaxPacketSize=        1024;
        Print("SIP_ST_CC_OE_CE - End UDP config");

        Print("SIP_ST_CC_OE_CE - Configuring UDP");
        UDP_Mgt_G ! Mgt_SL.Configure( ConfigUDP);
        
        Print("SIP_ST_CC_OE_CE - Activating UDP");
        UDP_Data_G ! PH_SL.PH_Act_Rq();
        START TAct_Rq FOR 10000;
    
        UDP_Data_G ? PH_SL.PH_Act_Ind() : PH_SL_S 
        {
            Print( "SIP_ST_CC_OE_CE - UPD Activated");
            START TSupervisor FOR 10000;
            
            Scenario_Gen_HTML_Verdict( HTML_File,
                                       0, 
                                       "PASS",
                                       "UDP activated");
            :: Wait_Invite;
        }
        
        UDP_Data_G ? PH_SL.PH_Deact_Ind() : PH_SL_S 
        {
            Print( "SIP_ST_CC_OE_CE - UPD Act_Rq not successfull  ... PH_Deact_Ind received!");
            
            Scenario_Gen_HTML_Verdict( HTML_File,
                                       1, 
                                       "FAIL",
                                       "UPD Act_Rq not successfull  ... PH_Deact_Ind received!");            
            STOP;
        }
        
        ? .TAct_Rq()
        {
            Print( "SIP_ST_CC_OE_CE - UPD Act_Req not received  ... Timeout!");
            Scenario_Gen_HTML_Verdict( HTML_File,
                                       1, 
                                       "FAIL",
                                       "UPD Act_Req not received  ... timeout!");
                                       
            STOP;
        }                
    }             
     
    STATE Wait_Invite
    {            
		Print("SIP_ST_CC_OE_CE - Starting");
		
		START TStart FOR 10000;
		
		? .TStart()
		{
            Print( "SIP_ST_CC_OE_CE - No call started  ... Timeout!");
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "No call started  ... timeout!"); 
            STOP;
        }
		
        SIP_G ? SIP_Signals_T.SIP_Invite (?) : SIP_Signal
		{
			Print("SIP_ST_CC_OE_CE - SIP_Invite message received");
			Print(SIP_Signal);
			
			
			Print(SIP_Signal.SIP_Invite.Request);
			Request_RX_1 = SIP_Signal.SIP_Invite.Request;
            Print(Request_RX_1);
			
            Scenario_Gen_HTML_Verdict( HTML_File, 0, "PASS", "Tester received INVITE from SUT");
			
			Status_Line 											= NULL;
			Status_Line.SIP_Version 								= Request_RX_1.Request_Line.SIP_Version;
			Status_Line.Status_Code 								= 486;
			Status_Line.Reason_Phrase.Token_List 					= "Busy Here";
            
			Message_Headers 										= NULL;
			Message_Headers.CSeq 									= Request_RX_1.Message_Headers.CSeq;
			Message_Headers.Call_Id 								= Request_RX_1.Message_Headers.Call_Id;
			Message_Headers.Contact 								= Request_RX_1.Message_Headers.Contact;
			Message_Headers.From									= Request_RX_1.Message_Headers.From;
			Message_Headers.To.To_Spec.Addr							= Request_RX_1.Message_Headers.To.To_Spec.Addr;
			Message_Headers.Via 									= Request_RX_1.Message_Headers.Via;
			Message_Headers.Supported								= Request_RX_1.Message_Headers.Supported;
			Message_Headers.Content_Length.ContentLength 			= 0;
			Message_Headers.User_Agent.Server_Val_List.Token_List 	= "SAFIRE 4G - SIP Signaling Tester";
			
			Message_Body											= NULL;
			
			Print("Message_Headers:");
			Print(Message_Headers);
			
			Response_T_TX_1.Status_Line 		= Status_Line;
			Response_T_TX_1.Message_Headers 	= Message_Headers;
			Response_T_TX_1.Message_Body 		= Message_Body;
			
            SIP_G ! SIP_Signals_T.SIP_486_Busy_Here (Response_T_TX_1);
            Print("SIP_ST_CC_OE_CE - SIP_486_Busy_Here sent");
			
			START TResponse FOR 1000;
            :: Wait_End_Test;
		}
		

    }

    STATE Wait_End_Test
    {        
        SIP_G ? SIP_Signals_T.SIP_Ack (?) : SIP_Signal 
        {
            Print("SIP_ST_CC_OE_CE - VERDICT: PASS! - SIP_Ack received");
            Scenario_Gen_HTML_Verdict( HTML_File, 0, "PASS", "SIP_Ack received");   
			:: Postamble;
        }       
        
        SIP_G ? SIP_Signals_T.SIP_Cancel (?) : SIP_Signal 
        {
            Print("SIP_ST_CC_OE_CE - VERDICT: FAIL! - SIP_Cancel received - SIP_Ack was expected");
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "SIP_Cancel received");
            :: Postamble;       
        }
        
        SIP_G ? ? : SIP_Signal 
        {                
            Print("SIP_ST_CC_OE_CE - VERDICT: FAIL! - Unexpected message received");
            Print(SIP_Signal);
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "Unexpected message received");                                 
            :: Postamble;
        }
        
     
        ? .TResponse()
        {
            Print("SIP_ST_CC_OE_CE - VERDICT: FAIL! - TResponse timer expiered");
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "TResponse timer expiered");                                  
            :: Postamble;
        }
        
        ? .TSupervisor()
        {
            Print("SIP_ST_CC_OE_CE - VERDICT: FAIL! - TSupervisor timer expiered");
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "TSupervisor timer expiered");
            :: Postamble;
        }
    }
    
    
	
	STATE Postamble
    {	
        Print("SIP_ST_CC_OE_CE - ... ending the test scenario");
		
        UDP_Data_G ! PH_SL.PH_Deact_Rq();
        Scenario_Gen_HTML_Footer( HTML_File);
        CloseFile( HTML_File);
        STOP;
    }
};